<?php

include_once('Database.php');
include_once('RestUtils.php');

/**
 * Gets the list of vehicles in JSON format
 */
function getVehicleList()
{
	$db = new DBManager();
	$mysqli = $db->db_connect();

	$query = "SELECT vehicleId FROM Vehicle";
	
	$stmt = $mysqli->prepare($query);
	$stmt->execute();
	$result = $stmt->get_result();

	$list = array();

	while($row = $result->fetch_assoc())
	{
		$list[] = array('vehicleId'=>$row['vehicleId']);
	}

	return json_encode($list);
}

/* Initialize the request
 *
 * Request format: PATH/VehicleList.php */
$requestData = RestUtils::processRequest();

/* Now let's handle the request */
switch($requestData->getMethod())
{
	/* If it was a GET request */
	case 'get':
		/* At this point the list of vehicles is wanted since no stationId is specified */
		$result = getVehicleList();

		/* Echo the result */
		echo RestUtils::sendResponse(200, $result, 'application/json');
		break;

	/* No need to implement POST, PUT and DELETE requests yet */
}

?>